<template>
	<view class="uni_box home">
		<navbar title='个人信息'>
		</navbar>
		<view class="content">
			<view class="infoview">
				<view class="infoitem"  v-if="info.avatar" @click="upload">
					<image class="bjtou" mode="aspectFill" :src="info.avatar" />
					<text class="xiutext">上传头像</text>
				</view>
				<view class="infoitem">
					<text class="infotext">姓名</text>
					<input v-model="info.nickname" class="bjinput" type="text" placeholder="请输入" placeholder-style="font-size: 30rpx;" />
					<image class="commicon" mode="" src="/static/commicon.png" />
				</view>
				<view class="infoitem" @click="getphone">
					<text class="infotext">手机号</text>
					<text>{{ mobile }}</text>
					<!-- <input v-model="mobile" class="bjinput" type="text"  placeholder="请输入"  placeholder-style="font-size: 30rpx;" disabled /> -->
					<image class="commicon" mode="" src="/static/img/icon_next.png" />
				</view>
				
			</view>
			<view class="botview">
				<view class="botitem" @click="xiugai">
					保存
				</view>

			</view>
		</view>
	</view>
</template>

<script>
    import {
		baseUrl
	} from '@/utils/config.js';
	export default {
		data() {
			return {
				value:'',
				type: 'text',
				border: false,
				head_portrait:'',//头像
				nickname:'',//昵称
				motto:'',//简介
				user:{},
				realname:{},
				headimg:'',
				pay_password:'',
                info:{
                    nickname:'',
                    avatar:'',
                    mobile:'',
                },
                mobile:''
			}
		},
		onLoad() {
			this.getinfo();//用户信息
		},
		onShow() {
		},
		methods: {
			async getinfo(){
				let res = await this.$u.api.user();
				// console.log(res)
				this.user = res.data
                this.info.nickname = res.data.nickname
                this.info.avatar = this.ossThree(res.data.avatar)
                this.info.mobile =  res.data.mobile
                this.mobile =  this.hideMiddleDigits(res.data.mobile)
			},
			shangchuan(){
				//e 1微信 2支付宝
				let that = this
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album','camera'], //从相册选择
					success: (re) => {
						uni.uploadFile({
						   url: baseUrl+'/api/common/upload', //仅为示例，非真实的接口地址
						   filePath: re.tempFilePaths[0],
						   name: 'file',
						   header: {
							ApiToken: uni.getStorageSync('token')
						   },
						   success: res => {
							console.log(JSON.parse(res.data))
							this.head_portrait = JSON.parse(res.data).data.src
							//    if(e == 1){
							// 	   //微信
							// 	   that.weixinImg = JSON.parse(res.data).msg
							//    }else if(e == 2){
							// 	   that.zhifuImg = JSON.parse(res.data).msg
							//    }
							// that.userInfo.head_portrait = JSON.parse(res.data).data.src
							// that.gettouxiang();//请求换头像接口
						   }
						})
					}
				});
			},
			upload(e) {
				// this.updatetype = e
				uni.chooseImage({
					count: 1,
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						this.headimg = tempFilePaths[0];
						// this.isClick = true;
						this.unloadtou()
					}
				});
			},
			unloadtou(){
				// console.log(this.head_portrait)
				let that = this
				uni.uploadFile({
					url: baseUrl + '/api/common/upload', //仅为示例，非真实的接口地址
					filePath: this.headimg,
					name: 'file',
					header: {
						// 'content-type': 'application/json;charset=UTF-8',
						'token': uni.getStorageSync('token'),
					},
					formData: {
						'token':uni.getStorageSync('token')
					},
					success: (uploadFileRes) => {
						if(JSON.parse(uploadFileRes.data).code == 1){
							that.info.avatar = that.ossThree(JSON.parse(uploadFileRes.data).data.url)
						}else{
							that.$u.toast(JSON.parse(uploadFileRes.data).msg);
						}
						// that.getinfo()
					}
				});
			},
			sexClick(e){
				this.user.sex = e
			},
			async xiugai(){
				if(!this.info.avatar){
					this.$u.toast('请上传头像');
					return false;
				}
				let res = await this.$u.api.profile(this.info);
				this.$u.toast('操作成功');
				this.getinfo()
				setTimeout(() => {
					uni.navigateBack({ delta: 1 })
				}, 1000);
			},
			backTo() {
				uni.navigateBack()
			},
            getphone(){
                this.navrouter("/pages/TPage/EditPhone");
            }
		}
	}
</script>

<style lang="scss" scoped>
	page{
		background-color: #fff;
	}
	.content{
		background-color: #fff;
		min-height: 100vh;
		.bjnav{
			display: flex;
			flex-direction: column;
			padding: 30rpx;
			.bjnavitem{
				display: flex;
				flex-direction: column;
				margin-top: 60rpx;
				.bjleft{
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #333333;
					display: block;
					margin-bottom: 20rpx;
				}
				.bjinput{
					height: 88rpx;
					background: #F7F7F7 !important;
					border-radius: 10rpx;
					color: #333;
					font-size: 28rpx;
					padding: 0 30rpx;
					min-width: 65%;
					
				}
			}
		}
		.infoview{
			display: flex;
			flex-direction: column;
			padding: 0 30rpx;
			.infoitem{
				display: flex;
				flex-direction: row;
				padding: 30rpx 0;
				align-items: center;
				border-bottom: 1rpx solid #eee;
				.bjtou{
					width: 124rpx;
					height: 124rpx;
					border-radius: 50%;
					margin-right: 80rpx;

				}
				/deep/.uni-input-input{
					width: 100%;
					height: 100%;
					font-size: 30rpx;
				}
				.commicon{
					margin-left: auto;
					width: 35rpx;
					height: 35rpx;
				}
				.infotext{
					font-size: 26rpx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #999999;
					width: 200rpx;
				}
				.xiutext{
					font-size: 30rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #666666;
				}
				.xbie{
					margin-left: auto;
					width: 40%;
					display: flex;
					flex-direction: row;
					justify-content: space-between;
					.xbieview{
						display: flex;
						flex-direction: row;
						align-items: center;
						.quans{
							width: 40rpx;
							height: 40rpx;
							margin-right: 6rpx;
						}
						text{
							font-size: 30rpx;
							font-family: PingFang SC;
							font-weight: 500;
							color: #111111;
						}
					}
				}
			}
		}
		.botview{
			position: fixed;
			width: 100%;
			height: 150rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			padding-bottom: 20rpx;
			bottom: 0;
			.botitem{
				width: 94%;
				margin: 0 auto;
				height: 88rpx;
				background: linear-gradient(90deg, #FF8F39, #FF4D43);
				border-radius: 45rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 26rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
			}

		}
	}
	/deep/ .u-input{
		background: #F7F7F7;
	}
</style>
